package org.ajc.auth.service.impl;

import org.ajc.auth.domain.Role;
import org.ajc.auth.dto.RoleDTO;
import org.ajc.auth.mapper.RoleMapper;
import org.ajc.auth.service.IRoleService;
import org.ajc.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ajc
 * @since 2024-01-19
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    @Transactional
    public void roleAuth(RoleDTO roleDTO) {
        // 清空对应的中间表
        roleMapper.deleteByRoleId(roleDTO.getRole());
        // 保存
        roleMapper.roleAuth(roleDTO);
    }

    @Override
    public void deleteByRoleId(Role role) {
        // 清空中间表的数据
        roleMapper.deleteByRoleId(role);
    }

    @Override
    public List<Long> queryAuthByRoleId(String id) {
        return roleMapper.queryAuthByRoleId(id);
    }
}
